﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using FlickrSample.SL.Infrastructure.Flickr.Entities;

namespace FlickrSample.SL.Infrastructure.Flickr.Parser
{
    public class PhotoSetParser
    {
        public static List<PhotoSet> ParsePhotoSet(string xml)
        {
            var doc = XDocument.Parse(xml);


            /*photosets>
	<photoset id="72157623885433363" primary="4585640079" secret="2779363b29" server="4045" farm="5" photos="3" videos="0">
		<title>New House</title>
		<description />
	</photoset>*/

            var result = new List<PhotoSet>();

            foreach (var photoset in doc.Root.Element("photosets").Elements("photoset"))
            {
                var newSet = new PhotoSet();

                newSet.Id = photoset.Attribute("id").Value;

                newSet.PhotoCount = Convert.ToInt32(photoset.Attribute("photos").Value);
                newSet.VideoCount = Convert.ToInt32(photoset.Attribute("videos").Value);

                newSet.Title = photoset.Element("title").Value;
                newSet.Description = photoset.Element("description").Value;
                result.Add(newSet);
            }

            return result;
        }
    }
}
